//
//  AddFoodListViewController.m
//  FoodCorner
//
//  Created by Summer on 16/3/11.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "AddFoodListViewController.h"
#import "TableFootView.h"
#import "TableHeaderView.h"
#import "CookStepsCell.h"
#import "AddCookModel.h"
#import <SDAutoLayout/UITableView+SDAutoTableViewCellHeight.h>
@interface AddFoodListViewController ()
@property (nonatomic,strong) TableHeaderView *tableHeader;
@property (nonatomic,strong) TableFootView *tableFootView;
@end
static NSString *identifier = @"cellID";
@implementation AddFoodListViewController


-(instancetype)initWithStyle:(UITableViewStyle)style
{
    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
        
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.hidesBackButton = YES;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItemStop) target:self action:@selector(backButtonAction)];
    _tableHeader = [[TableHeaderView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];
    
    _tableFootView = [[TableFootView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
    
    self.tableView.tableHeaderView = _tableHeader;
    
    self.tableView.tableFooterView = _tableFootView;
    
    [self.tableView registerClass:[CookStepsCell class] forCellReuseIdentifier:identifier];

}
- (void)backButtonAction
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Incomplete implementation, return the number of sections
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
    if (section ==  0) {
        return 1;
    }else
    {
        return 2;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CookStepsCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    
    // Configure the cell...
    cell.stepNumber.text = @"12";
    cell.stepInfoList.text = @"fjkjhfflwjfkjfhdgkhfeofhskdh";
    cell.stepImageView.image = [UIImage imageNamed:@"1"];
    return cell;
}



// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}



// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}



// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
    

}



// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
#pragma mark 自适应cell的实现方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AddCookModel *model = [AddCookModel new];
    if (model == nil) {
        return [self.tableView cellHeightForIndexPath:indexPath model:nil keyPath:nil cellClass:[CookStepsCell class] contentViewWidth:[self cellContentViewWith]];
    }else
    {
        return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[CookStepsCell class] contentViewWidth:[self cellContentViewWith]];
        
    }
}
- (CGFloat)cellContentViewWith
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    
    // 适配ios7
    if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 9.2) {
        width = [UIScreen mainScreen].bounds.size.height;
    }
    return width;
}



@end
